<template>
	<div id="scoreImpRecord">
		<div class="recordHead">
			<span class="recordTitle">导出记录</span>
			<span class="turnOff" @click="cancle()">关闭</span>
		</div>
		<div class="list">
			<el-table :data="list">
				<el-table-column prop="index" label="序号" width="70">
				</el-table-column>
				<el-table-column prop="exportType" label="导出表格类型">
				</el-table-column>
				<el-table-column prop="dataSize" label="数据条数">
				</el-table-column>
				<el-table-column prop="exportor" label="导出人">
				</el-table-column>
				<el-table-column prop="exportTime" label="导出时间">
				</el-table-column>
				<el-table-column label="导出发送状态" align="center">
					<template scope="scope">
						<span v-if="scope.row.status ==0">导出中</span>
						<span v-if="scope.row.status ==1">成功</span>
						<br>
						<a v-if="scope.row.status ==1 && scope.row.fileUrl" :href="scope.row.fileUrl">点击下载</a>
						<a v-if="scope.row.status ==1 && !scope.row.fileUrl">点击下载</a>
						<span v-if="scope.row.status ==2">导出失败</span>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<v-footer></v-footer>
	</div>
</template>

<script>
	import { mapState, mapActions } from "vuex";
	import vFooter from "../../common/Footer.vue";
	export default {
		components: {
			vFooter
		},
		data() {
			return {
				list: []
			};
		},
		computed: mapState({ user: state => state.user }),
		mounted() {
			this.exportHistory();
			this.interval = setInterval(() => {
				this.exportHistory();
			}, 10000);
		},
		methods: {
			exportHistory() {
				let url = this.$util.domain + "/scoreexport/list";
				this.list = [];

				this.$http({
					url,
					method: "POST",
					body: JSON.stringify({
						rootUnid: parseInt(this.user.rootUnid)
					})
				}).then(response => {
					if (response.data.error == 10000) {
						let importList = response.data.data;
						if (importList && importList.length > 0) {
							for (let i = 0; i < importList.length; i++) {
								let $index = i + 1,
									$exportType = importList[i].exportType,
									$dataSize = importList[i].dataSize,
									$exportor = importList[i].exportor,
									$exportTime = new Date(importList[i].exportTime).format("yyyy/MM/dd hh:mm"),
									$status = importList[i].status,
									$fileUrl = importList[i].fileUrl;
								if ($exportType == 1) {
									$exportType = "跑步明细";
								} else if ($exportType == 2) {
									$exportType = "跑步统计";
								}

								this.list.push({
									index: $index,
									status: $status,
									fileUrl: $fileUrl,
									exportor: $exportor,
									dataSize: $dataSize,
									exportTime: $exportTime,
									exportType: $exportType
								});
							}
						}
					}
				});
			},
			cancle() {
				location.href = "/#/scoreImport";
			}
		},
		beforeDestroy() {
			clearInterval(this.interval);
		}
	};
</script>
<style scoped>
	#scoreImpRecord {
		height: calc(100% - 100px);
		padding-bottom: 60px;
	}

	.recordHead {
		height: 60px;
		background-color: #2d3243;
	}

	.recordTitle {
		color: #ffffff;
		line-height: 60px;
		padding-left: 50px;
	}

	.turnOff {
		color: #ffffff;
		float: right;
		padding-right: 50px;
		line-height: 60px;
		cursor: pointer;
	}

	#scoreImpRecord .list {
		height: calc(100% - 80px);
	}
</style>